// Created by Roman Novitsky on 21.04.2009


#region Imported Namespaces


using System;
using System.Globalization;
using System.Windows.Data;


#endregion


namespace WtfManager.FileManager
{
  ///<summary>
  /// Converts path string to a <see cref="FileSystemItem">file system items</see> and back.
  ///</summary>
  [ValueConversion(typeof(String), typeof(FileSystemItem))]
  public class PathToFileSystemItemConverter: IValueConverter
  {
    #region Fields


    private static PathToFileSystemItemConverter _instance;


    #endregion


    #region Properties/Indexers


    ///<summary>
    /// Gets an instance of <see cref="PathToFileSystemItemConverter"/>
    ///</summary>
    public static PathToFileSystemItemConverter Instance
    {
      get
      {
        if (_instance == null)
        {
          _instance = new PathToFileSystemItemConverter();
        }

        return _instance;
      }
    }


    #endregion


    #region Methods


    /// <summary>
    /// Converts a value. 
    /// </summary>
    /// <returns>
    /// A converted value. If the method returns null, the valid null value is used.
    /// </returns>
    /// <param name="value">The value produced by the binding source.
    ///                 </param><param name="targetType">The type of the binding target property.
    ///                 </param><param name="parameter">The converter parameter to use.
    ///                 </param><param name="culture">The culture to use in the converter.
    ///                 </param>
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      return FileSystemItemToPathConverter.Instance.ConvertBack(value, targetType, parameter, culture);
    }


    /// <summary>
    /// Converts a value. 
    /// </summary>
    /// <returns>
    /// A converted value. If the method returns null, the valid null value is used.
    /// </returns>
    /// <param name="value">The value that is produced by the binding target.
    ///                 </param><param name="targetType">The type to convert to.
    ///                 </param><param name="parameter">The converter parameter to use.
    ///                 </param><param name="culture">The culture to use in the converter.
    ///                 </param>
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      return FileSystemItemToPathConverter.Instance.Convert(value, targetType, parameter, culture);
    }


    #endregion
  }
}